﻿using Service;
using Microsoft.AspNetCore.Mvc;
using MyProject;
using Dto;

namespace Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class User2Controller : BaseController
    {
        public IFreeSql _fsql;

        public User2Controller(IFreeSql fsql)
        {
            _fsql = fsql;
        }
        [HttpPost]
        public ApiModel Find([FromBody] UserDto dto)
        {
            var repo = _fsql.Select<User>();
            var item = repo.Include(a=>a.Ext).Where(a => a.Id == dto.Id).ToList();
            if (item == null)
            {
                return apiModel(Status.Error,"没有此用户");
            }
            else{
                return apiModel(Status.Success, "", item[0]);
            }
        }
        [HttpPost]
        public ApiModel FindAll()
        {
            var repo = _fsql.Select<User>().Include(a => a.Ext).Include(a => a.Group).ToList(c=>c.GroupId);
            //var repo = _fsql.Select<User>().ToList(true);
            if (repo == null)
            {
                return apiModel(Status.Error,"没有此用户");
            }
            else{
                return apiModel(Status.Success, "", repo);
            }
        }
    }
}
